var pageParam = null;

$(function() {
	$('#vue_vm_list div').hide();
	
	var pageParamStr = $.url().param('pageParam');
	pageParam = JSON.parse(pageParamStr);
	showParamInfo(pageParam);
});

function showParamInfo(pageParam) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	$('#vue_vm_list').html(gl_vue_vm_list_html);
	
	new Vue({
		el: '#vue_vm_list',
		data: {
			todos: [pageParam]
		},
		methods: {
			getPayWayName: function(payWay) {
				var payWayName = '其他';
				
				switch(payWay) {
					case 1:
						payWayName = '现金';
						break;
					case 2:
						payWayName = '钱包扣费';
						break;
					case 3:
						payWayName = '五保免租金';
						break;
					case 4:
						payWayName = '五保免租金押金';
						break;
				}
				
				return payWayName;
			},
			
			onDayNumChange: function(leaseId, rent) {
				var leaseAdd = {};
				leaseAdd.days = parseInt($('#'+leaseId+'_dayNum').val());
				leaseAdd.totalFee = rent * leaseAdd.days;
				$('#'+leaseId+'_totalFee').text(leaseAdd.totalFee+'元');
				return leaseAdd;
			},
			
			dateDiff: function(sDate1, sDate2) {
				if(!sDate1||!sDate2){
					return "未知"
				}
				return DateDiff(sDate1, sDate2);
			},
			
			getNowDate: function() {
				return getNowFormatDate().substr(0,10);
			},
			
			getNowDiff: function(sDate1) {
				var nowDate = getNowFormatDate().substr(0,10);
				return DateDiff(nowDate, sDate1);
			},
			
			getNowDiffText: function(sDate1) {
				var nowDiff = this.getNowDiff(sDate1);
				return nowDiff>=0?'还有'+nowDiff+'天到期':'已经超期'+(-nowDiff)+'天';
			},
			
			getNowDiffStart: function(sDate2) {
				var nowDate = getNowFormatDate().substr(0,10);
				var nowDiff = DateDiff(nowDate, sDate2);
				return nowDiff;
			},
			
			getReturnTimeDiffStart: function(leaseForm) {
				var returnTime = getStandardDay(leaseForm.returnYear, leaseForm.returnMonth, leaseForm.returnDay);
				var diff = DateDiff(returnTime, leaseForm.leaseStartTime);
				return diff;
			},
			
			getRealRentTotal: function(leaseForm) {
				var realRentTotal;
				if(leaseForm.payWay==3 || leaseForm.payWay==4) {
					realRentTotal = 0;
				}else {
					realRentTotal = leaseForm.leaseSupplyForm.rent*this.getReturnTimeDiffStart(leaseForm);
				}
				
				return realRentTotal;
			},
			
			getRealPledge: function(leaseForm) {
				return leaseForm.officialPledge;
			},
			
			getAlreadyRentTotal: function(leaseForm) {
				var totalRent;
				if(leaseForm.payWay==3 || leaseForm.payWay==4) {
					totalRent = 0;
				}else {
					totalRent = leaseForm.officialRent;
				}
				
				return totalRent;
			},
			
			getAlreadyPledge: function(leaseForm) {
				return this.getRealPledge(leaseForm);
			},
			
			getRealPayTotal: function(leaseForm) {
				return this.getRealRentTotal(leaseForm)+this.getRealPledge(leaseForm);
			},
			
			getAlreadyPay: function(leaseForm) {
				return this.getAlreadyRentTotal(leaseForm)+this.getAlreadyPledge(leaseForm);
			},
			
			getMoneyToReturn: function(leaseForm) {
				return this.getAlreadyPledge(leaseForm)+this.getAlreadyRentTotal(leaseForm)-this.getRealRentTotal(leaseForm);
			},
			
			getOfficialReturnMoney: function(leaseForm) {
				return leaseForm.returnMoney;
			}
		}
	});
	
	$('#vue_vm_list div').show();
}

function deleteBatch() {
	deleteBatch_basic(path+'/lease/deleteBatch');
}
